//
//  JQFYAvtivityHeaderView.m
//  JQFY
//
//  Created by apple on 2017/10/8.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYAvtivityHeaderView.h"

static NSInteger JQFYAvtivityHeaderViewButtonTag = 237;
static NSInteger JQFYAvtivityHeaderViewMargin = 10;
#define JQFYAvtivityHeaderViewButtonWidth (DH_Screen_Width - JQFYAvtivityHeaderViewMargin * 4) / 3
#define JQFYAvtivityHeaderViewButtonHeight JQFYAvtivityHeaderViewButtonWidth * 120 / 215

@interface JQFYAvtivityHeaderView ()

@property (nonatomic, strong)NSArray *buttons;

@end


@implementation JQFYAvtivityHeaderView

+ (CGFloat)heightForView {
    return 7  *SCAL+ JQFYAvtivityHeaderViewButtonHeight + 15 *SCAL;
}

- (instancetype)initWithReuseIdentifier:(nullable NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    NSMutableArray *mutableArray = [NSMutableArray array];
    for (int i = 0; i < 3; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *str = [NSString stringWithFormat:@"avtivityCell__%d",i + 1];
        [button setBackgroundImage:[UIImage imageNamed:str]forState:UIControlStateNormal];
        button.tag = JQFYAvtivityHeaderViewButtonTag + i;
        button.layer.cornerRadius = 12 *SCAL;
        button.layer.masksToBounds = YES;
        [button addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:button];
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).offset((JQFYAvtivityHeaderViewButtonWidth + JQFYAvtivityHeaderViewMargin) * i + JQFYAvtivityHeaderViewMargin);
            make.top.equalTo(self).offset(JQFYAvtivityHeaderViewMargin);
            make.height.mas_equalTo(JQFYAvtivityHeaderViewButtonHeight);
            make.width.mas_equalTo(JQFYAvtivityHeaderViewButtonWidth);
        }];
        [mutableArray addObject:button];
    }
    _buttons = mutableArray.copy;
}

- (void)tapAction:(UIButton *)button {
    NSInteger index = button.tag - JQFYAvtivityHeaderViewButtonTag;
    NSLog(@"点击了第%ld个button", index);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
